<script>
    var u = navigator.userAgent;
    var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
    var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
    var formurl = '/{php echo createMobileUrl("main",array("themeid"=>$themeid,"mod"=>"userdata","type"=>1,"op"=>"addlog"));}';

    if (isAndroid) { //安卓
        if (window.addEventListener) {
            document.addEventListener("visibilitychange", function () { //部分手机可以获取到
                // do something
                if (document.hidden) {
                    console.log(localStorage.getItem('isOut6'));
                    // $.ajaxSettings.async = false; //无效
                    navigator.sendBeacon(formurl);//formurl写后台接受数据地址
                    // sendAjax("getSysTimes", "get", function () { //发送请求
                    //     console.log(result)
                    // })
                    console.log('页面挂起')
                }else{
                    console.log('页面呼出')
                }
            })
        } else if (window.attachEvent) {
            // 主要是为了兼容老的IE
            window.attachEvent('onpagehide', function () {
                localStorage.setItem('isOut5', false)
                navigator.sendBeacon(formurl);//formurl写后台接受数据地址
                console.log(localStorage.getItem('isOut5'));
            })
        } else {
            window.onbeforeunload = function () {
                localStorage.setItem('isOut5', false)
                navigator.sendBeacon(formurl);//formurl写后台接受数据地址
                console.log(localStorage.getItem('isOut5'));
            }
        }
    }
    if (isiOS) { //苹果
        window.addEventListener("pagehide", function (e) {
            $.ajaxSettings.async = false; //无效
            navigator.sendBeacon(formurl);//formurl写后台接受数据地址
        }, false);
    }


    function doAddlog(type,remark){
        $.ajax({
            type: 'POST',
            dataType : "json",
            url:'/{php echo createMobileUrl("main",array("themeid"=>$themeid,"mod"=>"userdata","op"=>"addlog"));}',
            data: {type:type,remark:remark},
            success: function(data) {
            }
        });
    }

</script>